package io.renren.modules.generator.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.CommodityDao;
import io.renren.modules.generator.entity.CommodityEntity;
import io.renren.modules.generator.service.CommodityService;


@Service("commodityService")
public class CommodityServiceImpl extends ServiceImpl<CommodityDao, CommodityEntity> implements CommodityService {



    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CommodityEntity> page = this.page(
                new Query<CommodityEntity>().getPage(params),
                new QueryWrapper<CommodityEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public boolean like(String commodityId) {
        CommodityEntity commodityEntity = this.getById(commodityId);
        commodityEntity.setCommodityLike(commodityEntity.getCommodityLike()+1);
        return this.saveOrUpdate(commodityEntity);
    }

    @Override
    public boolean dislike(String commodityId) {
        CommodityEntity commodityEntity = this.getById(commodityId);
        commodityEntity.setCommodityLike(commodityEntity.getCommodityDislike()+1);
        return this.saveOrUpdate(commodityEntity);
    }
}